<template>
  <div class="box">
    <!-- 轮播图 -->
    <el-carousel :interval="3000" type="card" height="220px" class="carousel">
      <el-carousel-item v-for="(item, index) in carouselData" :key="index">
        <img :src="item.imageUrl" />
      </el-carousel-item>
    </el-carousel>
    <!-- 推荐歌单 -->
    <div class="recommend">
      <p>推荐歌单></p>
      <div class="cardBox">
        <songItem
          v-for="item in songItemData"
          :key="item.id"
          :itemData="item"
          class="songItem"
          @handleClick="handleClick"
        ></songItem>
      </div>
    </div>
  </div>
</template>
<script>
import songItem from './components/songItem.vue'
import { getCarouselData, getRecommendData } from '@/api/discover/recommend.js'
export default {
  name: 'recommendPage',
  data() {
    return {
      carouselData: [], // 轮播图数据
      songItemData: [] // 推荐歌单数据
    }
  },
  created() {
    this.getCarouselData()
    this.getSongItemData()
  },
  methods: {
    async getCarouselData() {
      const res = await getCarouselData()
      // console.log(res)
      this.carouselData = res.data.banners
    },
    async getSongItemData() {
      const res = await getRecommendData()
      this.songItemData = res.data.result
      // console.log(res.data.result)
    },
    // 跳转歌单详情
    handleClick(id) {
      this.$router.push({ path: '/index/musicDateil', query: { id } })
      // console.log(id)
    }
  },
  components: {
    songItem
  }
}
</script>
<style lang="scss" scoped>
.box {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  .recommend {
    width: 1200px;
    height: 446px;

    p {
      font-size: 25px;
      font-weight: 700;
    }
  }
}
.carousel {
  margin-top: 30px;
  width: 1000px;
  img {
    width: 100%;
    height: 100%;
  }
}

.el-carousel__item {
  border-radius: 10px;
}
:deep(.el-carousel__button) {
  width: 40px;
  height: 4px;
}
.cardBox {
  display: flex;
  flex-wrap: wrap;
  margin-top: 20px;
  .songItem {
    flex: 18%;
    margin-right: 20px;
    cursor: pointer;
    margin-bottom: 15px;
    &:nth-child(5n) {
      margin-right: 0;
    }
  }
  // .songItem:nth-child(5n) {
  //   margin-right: 0;
  // }
}
</style>
